package com.wangrui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wangrui.pojo.UserRole;
import com.wangrui.mapper.UserRoleMapper;
import com.wangrui.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王锐
 * @since 2020-07-08
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
    @Autowired
    private UserRoleMapper userRoleMapper;


    @Override
    public int addUserRole(UserRole userRole) {
        return userRoleMapper.insert(userRole);
    }

    @Override
    public int updateUserRole(UserRole userRole) {
        return userRoleMapper.updateById(userRole);
    }

    @Override
    public UserRole queryUserRoleByUserId(Integer userId) {
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userid",userId);
        UserRole userRole = userRoleMapper.selectOne(queryWrapper);
        if (userRole == null) {
            return null;
        }
        return userRole;
    }
}
